/*
 * Copyright 2011-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.platform.system.authn.action;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import me.ijleex.platform.framework.entity.Result;
import me.ijleex.platform.framework.spring.ControllerSupport;

/**
 * SystemAction.
 *
 * @author liym
 * @since 2021-07-21 16:58 新建
 */
@RequestMapping(path = "/system")
@RestController
public class SystemAction extends ControllerSupport<Result> {

    @GetMapping(path = "/admin-info")
    public Result getAdminInfo(HttpServletRequest request) {
        // 从 HTTP 头信息中获取 X-Token
        String token = request.getHeader("X-Token");
        logger.info("getAdminInfo Token: {}", token);

        Map<String, Object> data = new HashMap<>(8);
        data.put("name", "ijliym");
        data.put("introduction", "I am the super administrator");
        data.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        data.put("roles", Collections.singleton("ADMIN"));
        return Result.ok("OK").addData(data);
    }

    @PostMapping(path = "/ping")
    public Result ping(HttpServletRequest request) {
        return Result.ok("OK");
    }

}
